package com.atguigu.java.ai.langchain4j.config;

import com.atguigu.java.ai.langchain4j.store.MongoChatMemoryStore;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: LZY
 * @Date: 2025/09/01 19:56
 * @Description:
 **/
@Configuration // Spring 核心注解，它用于标记一个类为 “配置类
public class SeparateChatAssistantConfig {
    //注入持久化对象
    @Autowired
    private MongoChatMemoryStore mongoChatMemoryStore;

    //隔离聊天记忆+聊天存储
    @Bean
    ChatMemoryProvider chatMemoryProvider() {
        return memoryId -> MessageWindowChatMemory.builder()
                .id(memoryId) //memoryId 对话的id
                .maxMessages(10) //设置聊天记忆记录的最多message数量
                .chatMemoryStore(mongoChatMemoryStore)//配置持久化对象 实现聊天存储的功能
                .build();
    }

    //隔离聊天记忆
//    @Bean
//    ChatMemoryProvider chatMemoryProvider() {
//        return memoryId -> MessageWindowChatMemory.builder()
//                .id(memoryId) //memoryId 对话的id
//                .maxMessages(10) //设置聊天记忆记录的最多message数量
//                .build();
//    }

}
